<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>父子传参</title>
    <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
    <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>

<body>
    <div id="root"></div>
    <div id="root2"></div>
    <div id="root3"></div>
    <script type="text/babel">
        function Hello(props) {
            return <div>
                <p>name: {props.name}</p>
                <p>age: {props.age}</p>
                <p>sex: {props.sex}</p>
            </div>
        }

        // 语法糖方式
        ReactDOM.render(<Hello name="后端码匠" age="15" sex="男" />, root)

        // 类方式实现
        class HelloClass extends React.Component {
            render() {
                // 注意这里需要加括号
                return (
                    <div>
                        <p>name: {this.props.name}</p>
                        <p>age: {this.props.age}</p>
                        <p  >sex: {this.props.sex}</p>
                    </div>
                )
            }
        }

        // 注意方法后缀 .render()
        ReactDOM.render(new HelloClass({ name: "后端码匠2", age: "18", sex: "男" }).render(), root2)
        // 语法糖 写法较好看
        ReactDOM.render(<HelloClass name="后端码匠3" age="18" sex="男" />, root3);

    </script>
</body>

</html>